//The big RPG: written by Will Earnshaw
//with help from Leon Phillips and Kohaku
//
//Lisenced (apparently) with the GNU public 2.0 http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
//
//check out http://code.google.com/p/willisphat/

#include <iostream>
#include <string>
#include <windows.h>

using namespace std;

#include "diablo 2.h"
#include "int to string.h"

void story();
void loading();
void loadItems();
void loadCharacters();
void loadQuests();
void loadLocations();
void playerOptions();
void updatePlayer();
void lookPlayer();
void set_color(int a);
void calculateStats();
void loadSkills();
bool checkMove(location area);
void playerMove();

#include "load.h"

int main()
{
	loading();
	story();

	//main game loop woo! :):):):):):):)
	while(1)
	{
		system("cls");
		calculateStats();
		updatePlayer();
		playerOptions();
	}
	//this is well batty the loops over :(:(:(:(:(
	
	system("pause");

	return(0);
}

void updatePlayer()
{
	cout << player.currentLocation.area << endl << endl <<player.currentLocation.areaDescription << endl << endl;
	
	if(player.currentLocation.nameOfAreaOfInterest == "") 
	{
		cout << "There is little else of interest here" << endl;

	}else
	{
		cout << "There is a " << player.currentLocation.nameOfAreaOfInterest << " in this area." << endl;
	}
}
void playerOptions()
{
	string descision;

	cout << "What would you like to do? :";
	cin >> descision;
	cout << endl;

	if(descision == "look")
	{
		string lookDescision;

		cout << "What do you want to look at? :";
		cin >> lookDescision;
		cout << endl;

		if(lookDescision == player.name ||lookDescision == "me")
		{
			lookPlayer();
		}else if(lookDescision == player.currentLocation.nameOfAreaOfInterest)
		{
			cout << "You look at the " << player.currentLocation.nameOfAreaOfInterest << endl;
			cout << endl;
			cout << player.currentLocation.areaOfInterestDescription << endl;
		}else{
			cout << "You cannot see a " << lookDescision << " please check your spelling/make sure this is a valid command." << endl;
			system("pause");
		}

	}else if(descision == "move" || descision == "go")
	{
		playerMove();
	}
	else{
			cout << "Sorry, this game dosn't understand " << descision << " please check your spelling/make sure that is a valid command."<< endl << endl;
			system("pause");
	}
}

void lookPlayer()
{
	cout << "You look at yourself." << endl;
	cout << endl;
	cout << player.description;
	cout << endl;
	cout << "Status" << endl;
	cout << "------" << endl;
	cout << "Name :" << player.name << endl;
	cout << endl;
	cout << "Level :" << player.level << "\t\tEXP :" << player.exp << endl;
	cout << "Gold Pieces :" << player.gold << endl;
	cout << endl;
	cout << "HP :" << player.currentHP << "/" << player.HP << "\t\tMP :"<< player.currentMP << "/" << player.MP << endl;
	cout << endl;
	cout << "Strength :" << player.strength << endl;
	cout << "Magic :" << player.magic << endl;
	cout << "Agillity :" << player.agility << endl;
	cout << "Defence :" << player.defence << endl;
	cout << endl;
	cout << "Skills" << endl;
	cout << "------" << endl;
	cout << "LumberJack :" << player.treeLevel << endl; 
	cout << "FisherMan :" << player.fishingLevel << endl;
	cout << "BlackSmith :" << player.blackSmithLevel << endl;
	cout << "Mining :" << player.miningLevel << endl;
	cout << "Cooking :" << player.cookingLevel << endl;
	
	system("pause");
	system("cls");

	cout << "You are currently wearing :" << endl;
	cout << endl;
	
	cout << "Head" << endl <<  "----" << endl;

	if(player.armorHead.name == "") // check if you are wearing a helmet
	{
		cout << "You dont have anything equipped.";
	}
	else{

		set_color(player.armorHead.rarerity);
		cout << endl;
		cout << player.armorHead.name << endl;
		cout << endl;
		cout << player.armorHead.description << endl;
		cout << endl;
	}

	cout << endl << endl;
	set_color(WHITE);
	system("pause");
	system("cls");

	cout << "Arms" << endl << "----" << endl;

	if(player.armorArms.name == "") 
	{
		cout << "You dont have anything equipped.";
	}
	else{

		set_color(player.armorArms.rarerity);
		cout << endl;
		cout << player.armorArms.name << endl;
		cout << endl;
		cout << player.armorArms.description << endl;
		cout << endl;
	}

	cout << endl << endl;
	set_color(WHITE);
	system("pause");
	system("cls");

	cout << "Chest" << endl << "-----" << endl;

	if(player.armorChest.name == "") 
	{
		cout << "You dont have anything equipped.";
	}
	else{

		set_color(player.armorChest.rarerity);
		cout << endl;
		cout << player.armorChest.name << endl;
		cout << endl;
		cout << player.armorChest.description << endl;
		cout << endl;
	}
	
	cout << endl << endl;
	set_color(WHITE);
	system("pause");
	system("cls");

	cout << "Legs" << endl << "----" << endl;

	if(player.armorLegs.name == "") 
	{
		cout << "You dont have anything equipped.";
	}
	else{

		set_color(player.armorLegs.rarerity);
		cout << endl;
		cout << player.armorLegs.name << endl;
		cout << endl;
		cout << player.armorLegs.description << endl;
		cout << endl;
	}

	cout << endl << endl;
	set_color(WHITE);
	system("pause");
	system("cls");

	cout << "Feet" << endl << "----" << endl;

	if(player.armorFeet.name == "") // check if you are wearing a helmet
	{
		cout << "You dont have anything equipped.";
	}
	else{

		set_color(player.armorFeet.rarerity);
		cout << endl;
		cout << player.armorFeet.name << endl;
		cout << endl;
		cout << player.armorFeet.description << endl;
		cout << endl;
	}

	cout << endl << endl;

	set_color(WHITE);
	system("pause");
	system("cls");

	cout << "Main Hand" << endl << "---------" << endl;

	if(player.mainHand.name == "")
	{
		cout << "You dont have anything equipped.";
	}
	else{

		set_color(player.mainHand.rarerity);
		cout << endl;
		cout << player.mainHand.name << endl;
		cout << endl;
		cout << player.mainHand.description << endl;
		cout << endl;
	}

	cout << endl << endl;

	set_color(WHITE);
	system("pause");
	system("cls");

	cout << "Off Hand" << endl << "--------" << endl;

	if(player.offHand.name == "")
	{
		cout << "You dont have anything equipped.";
	}
	else{

		set_color(player.offHand.rarerity);
		cout << endl;
		cout << player.offHand.name << endl;
		cout << endl;
		cout << player.offHand.description << endl;
		cout << endl;
	}

	cout << endl << endl;
	
	set_color(WHITE);
	system("pause");
	system("cls");
}

void calculateStats()
{
	player.defence = player.armorArms.bonus + player.armorChest.bonus + player.armorFeet.bonus + player.armorHead.bonus + player.armorLegs.bonus;  
	player.minAttack = player.mainHand.effect + (player.strength / 2 + player.level);
	player.maxAttack = player.mainHand.maxEffect + (player.strength / 2 + player.level);
}

bool checkMove(location area)
{
	if(area.areaDescription == "")
	{
		return false; // if there is no description then this must be an illegal move
	}else
	{
		return true; // there is an area description....you can go there!
	}
}
void playerMove()
{
	location temp = player.currentLocation;

	cout << "You can go";
	
	if(player.currentLocation.north == true)
		cout << " North";
	
	if(player.currentLocation.south == true)
		cout << " South";

	if(player.currentLocation.east == true)
		cout << " East";

	if(player.currentLocation.west == true)
		cout << " West";

	string directionDescision;

	cout << ". Which way would you like to go? (DEBUG: x:" << player.currentLocation.xPosition  << " y:" << player.currentLocation.yPosition << ") : ";
	cin >> directionDescision;
	cout << endl;

	if(directionDescision == "north" || directionDescision == "North")
	{	
		if(player.currentLocation.north)
		{
			player.currentLocation = forest[player.currentLocation.xPosition][player.currentLocation.yPosition+1];
		}else
		{
			cout << "You can't go north.";
		}
	}

	if(directionDescision == "south" || directionDescision == "South")
	{	
		if(player.currentLocation.south)
		{
			player.currentLocation = forest[player.currentLocation.xPosition][player.currentLocation.yPosition-1];
		}
	}

	if(directionDescision == "east" || directionDescision == "East")
	{
		if(player.currentLocation.east)
		{
			player.currentLocation = forest[player.currentLocation.xPosition+1][player.currentLocation.yPosition];
		}
	}

	if(directionDescision == "west" || directionDescision == "West")
	{	
		if(player.currentLocation.west)
		{	
			player.currentLocation = forest[player.currentLocation.xPosition-1][player.currentLocation.yPosition];
		}
	}

	//check to see if its a valid location
	if(!(checkMove(temp)))
	{
		cout << "You cannot go " << directionDescision << "." << endl;
		player.currentLocation = temp;
	}

	system("pause");
}